#ifndef _GET_DETAIL_BY_ID_INCLUDED_
#define _GET_DETAIL_BY_ID_INCLUDED_

#include<iostream>
#include<string>
#include<cstring>
#include<fstream>
#include<map>
#include<vector>
#include<WinSock.h>
#include"UDTime.h"

#pragma comment(lib,"Ws2_32.lib")
const unsigned int HTTP_PORT = 8080;
using namespace std;

struct Seller
{
	string sellerId;
	int trust;
	Seller():sellerId(),trust(0){}
	Seller(string ID,int num):sellerId(ID),trust(num){};
};
class ProductDetail
{
public:
	ProductDetail(string sellerIdUrl,int sellerIdPagesNum,vector<string> vecKey,vector<string> vecDelKey, int priceLower, Time earliest);
	~ProductDetail();
	void Run();//Interface;
	void DBG_Run();//for debug
protected:
	int getWebPage(string& url); //download a web page into buffer
	void getSellerId();//such to get seller's sales history,and get productID
	void searchSellerHistoryForItemId();
	bool fdBackHtmlParser(ostream& fout);//get the string matches the specified regex from buffer;
	bool legalJudge(string price,string prodDesp);
	bool auction(string& itemId);// judge is a item is sold by aution
	void getDetailByItemId();
	void setMonMap();
	void outputItemIds();
	void DBG_getItemIds();
	void DBG_setMapSellers();
	void DBG_setMapItemIds();
	inline string getStr(string& src,int& startPos);
    inline int commaStr2int(string& str);
	inline Time str2Time(string time);
private:
	static const unsigned int BUFFER_SIZE = (1<<20);
	static const unsigned int ITEMS_PER_PAGE = 200;
	string sellerIdUrl;
	int sellerIdPagesNum;
	string feedBackUrl;
	string auctionUrl;
	string itemIdDetailUrl;
	string currSeller;
	string currItemId;
	int currTrust;
	vector<string> vecKeyWord;
	vector<string> vecDelKeyWord;
	int priceLower;
	char* buffer;
	int bytesReceived;
	Time eTime;
	map<string,int> mapSellers;
	map<string,Seller> mapItemId2Seller;
	map<string,int> mapMonStr2Int;
};

#endif